package sumline

type JSONLanguagesResult struct {
	Languages []SumLineLanguage `json:"languages"`
	Total     SumLineLanguage   `json:"total"`
}

type JSONFilesResult struct {
	Files []SumLineFile   `json:"files"`
	Total SumLineLanguage `json:"total"`
}

func NewJSONLanguagesResultFromSumLine(total *Language, sortedLangs Languages) JSONLanguagesResult {
	var langs []SumLineLanguage
	for _, language := range sortedLangs {
		l := SumLineLanguage{
			Name:      language.Name,
			FileCount: int32(len(language.Files)),
			Code:      language.Code,
			Comments:  language.Comments,
			Blanks:    language.Blanks,
		}
		langs = append(langs, l)
	}

	tol := SumLineLanguage{
		FileCount: total.Total,
		Code:      total.Code,
		Comments:  total.Comments,
		Blanks:    total.Blanks,
	}

	return JSONLanguagesResult{
		Languages: langs,
		Total:     tol,
	}
}

func NewJSONFileResultFromSumLine(total *Language, sortedFiles SumLineFiles) JSONFilesResult {
	tol := SumLineLanguage{
		FileCount: total.Total,
		Code:      total.Code,
		Comments:  total.Comments,
		Blanks:    total.Blanks,
	}

	return JSONFilesResult{
		Files: sortedFiles,
		Total: tol,
	}
}
